package com.example.controllor;

import com.example.common.Result;
import com.example.entity.Dingdanshenhe;
import com.example.service.DingdanshenheService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dingdanshenhe")
public class DingdanshenheControllor {

    @Resource
    DingdanshenheService dingdanshenheService;
    @PostMapping("/add")
    public Result add(@RequestBody Dingdanshenhe dingdanshenhe){
        dingdanshenheService.add(dingdanshenhe);
        return Result.success();
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        dingdanshenheService.delete(id);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Dingdanshenhe dingdanshenhe){
        dingdanshenheService.update(dingdanshenhe);
        return Result.success();
    }

    @GetMapping("/selectAll")
    public Result selectAll(Dingdanshenhe dingdanshenhe){
        List<Dingdanshenhe> dingdanshenheList = dingdanshenheService.selectAll(dingdanshenhe);
        return Result.success(dingdanshenheList);
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             Dingdanshenhe dingdanshenhe){
        PageInfo<Dingdanshenhe> pageInfo = dingdanshenheService.selectPage(pageNum, pageSize, dingdanshenhe);
        return Result.success(pageInfo);
    }
}
